package com.mickey.result;

import com.sun.org.apache.bcel.internal.classfile.Code;
import org.springframework.util.StringUtils;

public class CodeMsg {
    private int code;
    private String msg;

    public static CodeMsg SUCESS = new CodeMsg(0,"sucess");
    public static CodeMsg SESSION_ERROR = new CodeMsg(400100,"用户失效");
    public static CodeMsg SERVICE_ERROR =  new CodeMsg(500100,"服务端异常！");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101,"参数校验异常：%s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500102,"请求非法");
    public static CodeMsg ACCESS_LIMIT_RECHED = new CodeMsg(500103,"请求过于频繁");


    public static CodeMsg PASSWORD_NULL = new CodeMsg(500200,"密码不能为空");
    public static CodeMsg MOBILE_NULL = new CodeMsg(500300,"手机号不能为空");
    public static CodeMsg MOBILE_EMPTY = new CodeMsg(500400,"手机号不存在");
    public static CodeMsg MOBILE_ERR = new CodeMsg(500500,"密码错误");

    //秒杀模块
    public static CodeMsg MIAOSHA_STOCK_NOT = new CodeMsg(500600,"商品已经秒杀完毕");
    public static CodeMsg MIAOSHA_REPEATE = new CodeMsg(500601,"不能重复秒杀");
    public static CodeMsg MIAOSHA_FAIL = new CodeMsg(500602,"秒杀失败");


    //订单模块
    public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500700,"订单不存在");

    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public CodeMsg fillArgs(Object... args){
        int code = this.code;
        String message = String.format(this.msg,args);
        return new CodeMsg(code,message);
    }

}
